package com.lzw.mapper.dormitoryAdmin;

import com.lzw.pojo.Student;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DStudentManagementMapper {

    //查询学生
    List<Student> list(@Param("name") String name, @Param("gender") String gender, @Param("phone") String phone);

    //添加学生
    @Insert("INSERT INTO dormitorymanagement.student(name, username, password, gender, phone, email, dormitory_id, building_id, image)" +
            "VALUES (#{name}, #{username}, #{password}, #{gender}, #{phone}, #{email}, #{dormitoryId}, #{buildingId}, #{image})")
    void add(Student student);

    void delete(@Param("ids") List<Integer> ids);

    @Select("SELECT * FROM dormitorymanagement.student WHERE student_id = #{studentId}")
    Student getStudentById(Integer studentId);

    void update(Student student);

    //查看名字是否存在
    @Select("SELECT COUNT(*) FROM dormitorymanagement.student WHERE name = #{name}")
    int countByName(String name);

    //查看用户名是否存在
    @Select("SELECT COUNT(*) FROM dormitorymanagement.student WHERE username = #{username}")
    int countByUsername(String username);

    //查看电话是否存在
    @Select("SELECT COUNT(*) FROM dormitorymanagement.student WHERE phone = #{phone}")
    int countByPhone(String phone);
}
